<template>
  <div
    class="media-pubshow"
    :class="{'fetching-box': listFetching}">
    <el-container>
      <el-main class="leftMain">
        <div class="main-title">{{ $t('目录管理') }}</div>
        <media-menu-tree
          :is-can-check="true"
          :is-no-action="true"
          :highlight="false"
          :expand-on-click-node="false"
          @check="checkHandle"
          @myTop="myTopClick"
          :api-obj="menuApiObj"
          :api-type="'4'"
          node-key="groupScreen"
        />
      </el-main>
      <el-main class="rightMain">
        <!-- <div class="main-title">发布列表</div> -->
        <bs-main height="100%">
          <condition-row
            slot="header"
            @add="handCondition('add')"
            @del="handCondition('del')"
            @revoke="handCondition('revoke')"
            @edit="handCondition('edit')"
            @examine="handCondition('examine')"
            @refresh="handCondition('refresh')"
          >
          <download-excel
              slot="export"
              type="primary"
              class="export-excel-wrapper"
              :fetch="_handleExport"
              :fields="excelDataFields"
              worksheet="节目发布统计数据"
              name="节目发布统计数据.xls"
            >
              <bs-export-button-icon></bs-export-button-icon>
            </download-excel>

          </condition-row>
          <pagination
            slot="footer"
            :total="page.total"
            :page="page.current"
            :limit="page.size"
            :showAllChecked="true" 
            :allChecked="allSize"
            @all="handleChangeAllSize"
            @pagination="pageChange"></pagination>
          <list
            v-loading="listFetching"
            height="calc(100% - 15px)"
            ref="list"
            class="center"
            :list-data="mediaData"
            :has-select="true"
            :list-cols="listCols"
            :action-opts="actionOpts"
            :init-cols-props.sync="initColsProps"
            @sort="handleSort"
            @filter="handleFilter"
          >
            <template slot="auditStateSlot" slot-scope="{row}">
              {{ row.auditState | getAuditStateName(te) }}
            </template>
            <template slot="publishTypeSlot" slot-scope="{row}">
              {{ row.publishType | getPublishTypeName(te) }}
            </template>
            <template slot="operatingSlot" slot-scope="{row}">
              {{ row.operating | getOperatingName(te) }}
            </template>
            <template slot="createAtSlot" slot-scope="{row}">
              {{ row.createAt | formatDate($moment) }}
            </template>
          </list>
        </bs-main>
      </el-main>
    </el-container>

    <!-- 发布计划弹窗 -->
    <plant-dialog
      :form="plantDialog.form"
      :visible.sync="plantDialog.show"
      :op-type="plantDialog.opType"
      @addClick="handleAddClick"
      @updateClick="handleUpdateClick"></plant-dialog>

    <!-- 审核弹窗 -->
    <examine-dialog
      :visible.sync="examineDialog.show"
      :media-list="examineDialog.mediaList"
      :publish="examineDialog.publish"
      :examined="examineDialog.examined"
      @examine="handleExamine"
      @dbClick="_openPreView"></examine-dialog>

    <del-dialog
      :text="delDialog.text"
      :visible.sync="delDialog.show"
      :file="delDialog.file"
      @del="delDiaClick"
      @remove="delDiaRemove"></del-dialog>
    <!-- 预览弹窗 -->
    <preview-dialog :visible.sync="previewDialog.show" :pre-data="previewDialog.preData" />
  </div>
</template>

<script>
import DownloadExcel from 'vue-json-excel'
import MediaMenuTree from '../components/MediaMenuTree'
import List from '@/components/List'
import Pagination from '@/components/Pagination'
import ConditionRow from './components/ConditionRow'

import PlantDialog from './components/PlantDialog'
import ExamineDialog from '../components/ExamineDialog'
import DelDialog from './components/DelDialog'
import PreviewDialog from '../components/PreviewDialog'
import MediaApi from '@/api/media'
import CommonApi from '@/api/common'
import { createNamespacedHelpers } from 'vuex'
import {FILETYPE} from '../media-center/const'
const {mapActions} = createNamespacedHelpers('media')

export default {
  filters: {
    formatDate(v, $moment) {
      return $moment(v).format('YYYY-MM-DD HH:mm:ss')
    },
    getAuditStateName(v,te) {
      switch(Number(v)) {
        case 0: return te('待审核')
        case 1: return te('已通过')
        case -1: return te('已拒绝')
        case -2: return te('待二级审核')
        case -3: return te('待三级审核')
        default: 
      }
    },
    getPublishTypeName(v,te) {
      switch(Number(v)) {
        case 1: return te('常规')
        case 2: return te('紧急')
        default: 
      }
    },
    getOperatingName(v,te) {
      switch(Number(v)) {
        case 0: return te('无权操作')
        case 1: return te('可操作')
        case 2: return te('被锁定')
        default: 
      }
    }
  },
  components: {
    DownloadExcel,
    MediaMenuTree,
    List,
    Pagination,
    ConditionRow,
    PlantDialog,
    ExamineDialog,
    DelDialog,
    PreviewDialog
  },
  name: 'media-pubshow',
  data() {

    const headerContextMenus = {
      width: '120px',
      items: [
        'sortUp',
        'sortDown',
        'line',
        'cols'
      ]
    }

    return {
      menuApiObj: {
        get: MediaApi.getPubCatalogue
      },
      examineDialog: {
        show: false,
        mediaList:[],
         publish:true,//是否是发布审核
         examined:false, //是否审核过
      },
      plantDialog: {
        show: false
      },
      delDialog: {
        show: false,
        test: '',
        file: null
      },
      previewDialog: {
        show: false,
       
      },
      copyForm: {
        endDate: this.$moment().add(7, 'day').format('YYYY-MM-DD'),
        startDate: this.$moment().format('YYYY-MM-DD'),
        ignoreDownload: 0,
        keep: 0,
        name: '',
        preloadDatetime: this.$moment().add(1, 'day').format('YYYY-MM-DD 00:00:00'),
        _preloadDateBool: false,
        _preloadDatetimeDate: this.$moment().add(1, 'day').format('YYYY-MM-DD'),
        _preloadDatetimeTime: '00:00:00',
        programSchedulePlay: [],
        publishType: 1,
        week: ['1', '2', '3', '4', '5', '6', '7']
      },
      treeLoading: false,
      treeData: [],
      defaultCheckedKeys: [],
      contextMenuData: [],
      mediaData: [],
      listCols: [
        {label: '发布名称', prop: 'name', headerContextMenus, minwidth: 100},
        {label: '发布类型', prop: 'publishType', headerContextMenus, minwidth:100, slot: true},
        {label: '发布序号', prop: 'publishNo', headerContextMenus, minwidth:100},
        {label: '生效日期', prop: 'startDate', headerContextMenus, minwidth: 100},
        {label: '过期日期', prop: 'endDate', headerContextMenus, minwidth: 100},
        {label: '审核状态', prop: 'auditState', headerContextMenus, minwidth: 100, slot: true},
        {label: '所属分组', prop: 'terminalGroup', headerContextMenus, minwidth: 100},
        {label: '创建用户', prop: 'userName', headerContextMenus, minwidth: 100},
        {label: '可操作性', prop: 'operating', headerContextMenus, minwidth: 100, slot: true},
        {label: '创建日期', prop: 'createAt', headerContextMenus, minwidth: 100, slot: true},
      ],
      initColsProps: [
        'name',
        'publishType',
        'publishNo',
        'startDate',
        'endDate',
        'auditState',
        'terminalGroup',
        'userName',
        'operating',
        'createAt'
      ],
      initHeadmuneFlag: false,
      actionOpts: {
        show: false
      },
      page: {
        current: 1,
        size: 15,
        total: 0
      },
      checkLog: {
        checkedNodes: [],
        checkedKeys: [],
        halfCheckedNodes: [],
        halfCheckedKeys: [],
      },
      groupScreenIds: [],
      terminalGroupIds: [],
      t3arr: [], // 屏幕元素组
      lastFetchTop: false, // 用于刷新 上次请求是否是所有编排请求
      programListFetching: false,
      listFetching: false,
      sort: {
        orderType: 0,
        ordersParam: 'asc'
      },
      sortFieldMap: {
        'name': 1,
        'publishType': 2,
        'publishNo': 3,
        'startDate': 4,
        'endDate': 5,
        'auditState': 6,
        'terminalGroup': 7,
        'userName': 8,
        'operating': 9,
        'createAt': 10
      },
      allSize: false,
      excelDataFields: {},
      loading:null,
    }
  },
  created () {
    this.fetchList({noMenu: true})
  },
  mounted() {
  },
  methods: {
    ...mapActions(['setNeedFetching']),
    myTopClick() {
      this.fetchList({noMenu: true})
    },
    // 文件是否能操作
    isCanAction(file) {
      let pass = true
      if(!this.allSize) {
        let message = ''
        if (file instanceof Array) {
          file.forEach(item => {
            if (item.operating !== 1) {
              pass = false
              message = '有不可操作的编排单'
            }
          })
        } else if (!file) {
          pass = false
          message = '请先选择编排单'
        } else {
          if (file.operating !== 1) {
            pass = false
            message = '此编排单不可操作'
          }
        }
        !pass && this.$alert('提示', message)
      }
      return pass
    },
    getActiveItem() {
      let items = this.$refs.list.getActiveItem()
      return items.length === 1 ? items[0] : items.length === 0 ? null : items
    },
    checkHandle(data, {checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys}) {
      this.checkLog = {
        checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys
      }
      console.log({checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys})
      const Params = this.initFetchParams()
      if (Params) {
        const [a,b,t3arr] = Params
        const _terminalGroupIds = []
        const _groupScreenIds = []
        t3arr.forEach(item => {
          const [terminalGroupId, screenId] = item.groupScreen.split('#')
          _terminalGroupIds.push(Number(terminalGroupId))
          _groupScreenIds.push(Number(screenId))
        })
        this.terminalGroupIds = _terminalGroupIds
        this.groupScreenIds = _groupScreenIds
        this.t3arr = t3arr.slice()
      } else {
        this.terminalGroupIds = []
        this.groupScreenIds = []
        this.t3arr = []
      }
      
      this.page.current = 1
      this.fetchList()
      // console.log('----checkHandle', checkedKeys)
      // this.fetchList()
    },
    // getType3IdByTree(data, arr) {
    //   if (data.type === 3) {
    //     arr.push(data.id)
    //   }
    //   if (data.children && data.children.length > 0) {
    //     data.children.forEach(item => {
    //       this.getType3IdByTree(item, arr)
    //     })
    //   }
    // },
    
    handleSort({type, prop}) {
      if (this.sortFieldMap[prop]) {
        this.sort = {
          orderType: this.sortFieldMap[prop],
          ordersParam: type.toLowerCase()
        }
        this.fetchList()
      }
    },
    handleFilter(filterInfo) {
      console.log('filterInfo----', filterInfo)
    },
    async handleAddClick(form, cb) {
      console.log('add-form----', form)
      let _form = JSON.parse(JSON.stringify(form))
      if (!_form._preloadDateBool) {
        _form.preloadDatetime = ''
      } else {
        _form.preloadDatetime = `${_form._preloadDatetimeDate} ${_form._preloadDatetimeTime}`
      }
      delete _form._preloadDateBool
      delete _form._preloadDatetimeDate
      delete _form._preloadDatetimeTime
      // 添加目录终端
      // _form.groupScreenIds = this.groupScreenIds
      // _form.terminalGroupIds = this.terminalGroupIds
      _form.groupScreens = this.t3arr.map(item => item.groupScreen)
      console.log(_form, '----_form')
      try {
        const res = await MediaApi.addPubList(_form)
        console.log(res, '-----sssss')
        
        this.$message.success('新增成功')
        this.setNeedFetching({change: 'program'})
        console.log(res)
        this.fetchList()
        cb && cb()
      } catch (error) {
        cb && cb(true)
        console.log('MediaApi.addPubList---', error)
      }
    },
    async handleUpdateClick(form, cb) {
      console.log('add-form----', form)
      let _form = JSON.parse(JSON.stringify(form))
      if (!_form._preloadDateBool) {
        _form.preloadDatetime = ''
      } else {
        _form.preloadDatetime = `${_form._preloadDatetimeDate} ${_form._preloadDatetimeTime}`
      }
      delete _form._preloadDateBool
      delete _form._preloadDatetimeDate
      delete _form._preloadDatetimeTime
      // 添加目录终端
      // _form.groupScreenIds = this.groupScreenIds
      // _form.terminalGroupIds = this.terminalGroupIds
      // _form.groupScreens = this.t3arr.map(item => item.groupScreen)
      _form.groupScreens = form.groupScreens
      console.log(_form, '----_form')
      // 移除节目列表多余字段
      _form.programSchedulePlay.forEach(item => {
        delete item.id
        delete item.programName
      })
      try {
        const res = await MediaApi.editPubList(_form)
        
        console.log(res)
        this.$message.success('编辑成功')
        this.setNeedFetching({change: 'program'})
        this.fetchList()
        cb && cb()
      } catch (error) {
        cb && cb(true)
        console.log('MediaApi.addPubList---', error)
      }
    },
    handCondition(type, data) {
      console.log(type, data)
      switch(type) {
        case 'add':
          if (this.groupScreenIds.length < 1) return this.$alert('提示', '请至少选择一个屏幕')
          this._openAddView()
          break;
        case 'del':
          this._handleDel(
            this.getActiveItem()
          )
          break;
        case 'revoke':
          this._handleRevoke(
            this.getActiveItem()
          )
          break;
        case 'edit':
          this._openEditView(
            this.getActiveItem()
          )
          break;
        case 'examine':
          this._openCheck(
            this.getActiveItem()
          )
          break;
        case 'refresh':
          this._handleRefresh()
          break;
        default: console.log('未知操作');
      }
    },
    _openAddView() {
      const copyForm = JSON.parse(JSON.stringify(this.copyForm))
      this.plantDialog = {
        ...this.plantDialog,
        show: true,
        opType: '1',
        form: {
          ...copyForm
        }
      }
    },
    async _openEditView(file) {
      if (file instanceof Array) {
        return this.$alert('提示', '此操作不支持多选')
      }
      if (this.isCanAction(file)) {
        if (this.programListFetching) return false
        this.programListFetching = true
        try {
          
          const res = await MediaApi.getPubProgramList(file.id)
          const copyFile = JSON.parse(JSON.stringify(res))

          // 对预发布时间处理
          if (copyFile.preloadDatetime) {
            copyFile._preloadDateBool = true
            copyFile._preloadDatetimeDate = copyFile.preloadDatetime.split(' ')[0]
            copyFile._preloadDatetimeTime = copyFile.preloadDatetime.split(' ')[1]
          } else {
            copyFile.preloadDatetime = this.$moment().add(1, 'day').format('YYYY-MM-DD 00:00:00')
            copyFile._preloadDateBool = false
            copyFile._preloadDatetimeDate = this.$moment().add(1, 'day').format('YYYY-MM-DD')
            copyFile._preloadDatetimeTime = '00:00:00'
          }
          // 对星期处理
          copyFile.week = copyFile.week.split(',')

          this.plantDialog = {
            ...this.plantDialog,
            opType: '2',
            show: true,
            form: copyFile
          }
        } catch (error) {
          console.log(error)
          this.$alert('提示', '获取节目列表失败')
        } finally {
          this.programListFetching = false
        }
      }
    },
    async _openCheck(file) {
        if (file instanceof Array) {
        return this.$alert('提示', '此操作不支持多选')
      }
      if (!this.allSize && !file) return this.$alert('提示', '请先选择编排单')
      // if (file.isRoot || this.isCanAction(file)) {
        let params = {
          programScheduleId:file.id
        }
        const res = await MediaApi.getPubMediaListt(params)

        this.examineDialog = {
            ...this.examineDialog,
            show: true,
            mediaList:res,
            examined:file.auditState==1||file.auditState==-1
          }
       
    },
    async refreshPicture(path){
      const previewTokenRes = path ? await CommonApi.previewToken({path: encodeURIComponent(path)}) : null
      return previewTokenRes
    },
    async handleExamine(v, msg, cb) {
      const file = this.getActiveItem()
      try {
        let ids = []
        let queryData = {}
        if(this.allSize) {
          const groupScreens = this.t3arr.map(item => item.groupScreen)
          queryData = {
            allSize: this.allSize,
            total: this.page.total,
            groupScreens: groupScreens
          }
        } else {
          ids = file instanceof Array ? file.map(i => i.id) : [file.id]
        }
        const res = await MediaApi.auditPubList({
          ...queryData,
          programScheduleId: ids,
          auditState: v,
          auditReason: msg
        })
        cb && cb()
        this.allSize = false
        this.$message.success('审核成功')
        this.fetchList()
      } catch (error) {
        cb && cb(true)
        console.log('MediaApi.auditPubList---', error)
      }
    },
    _handleDel(file) {
      if (!this.allSize && !file) {
        this.$alert('提示', '请先选择编排单')
        return
      }
      if (this.isCanAction(file)) {
        this.delDialog = {
          text: '您是要彻底删除还是从本组移除',
          show: true,
          file
        }
      }
    },
    async delDiaClick(file) {
      // eslint-disable-next-line
      const bool = await this.$confirm('提示', '是否确认删除？')
      if (bool) {
        let queryData = {}
        if(this.allSize) {
          const groupScreens = this.t3arr.map(item => item.groupScreen)
          queryData = {
            allSize: this.allSize,
            total: this.page.total,
            groupScreens: groupScreens
          }
        }
        this.delMedia(file, queryData)
      }  
    },
    async delDiaRemove(file) {
      const menuInfo = this.initFetchParams()
      if (!menuInfo) return this.$alert('提示', '请选择目录')
      const [a, b, t3arr] = menuInfo
      if (t3arr.length < 1) return this.$alert('提示', '请选择屏幕')
      
      const programScheduleId = file instanceof Array ? file.map(f => f.id) : [file.id]
      // const groupScreenIds = this.groupScreenIds
      // const terminalGroupIds = this.terminalGroupIds
      const groupScreens = this.t3arr.map(item => item.groupScreen)
      try {
        let queryData = {}
        if(this.allSize) {
          queryData = {
            allSize: this.allSize,
            total: this.page.total
          }
        }
        const res = await MediaApi.removePubList({
          ...queryData,
          programScheduleId,
          groupScreens
          // groupScreenIds,
          // terminalGroupIds
        })
        
        this.$message.success('移除成功')
        this.setNeedFetching({change: 'program'})
        this.fetchList()
      } catch (error) {
        console.log('delDiaRemove---', error)
      }
    },
    async _handleRevoke(file) {
       if (this.allSize || file instanceof Array) {
        return this.$alert('提示', '此操作不支持多选')
      }
      if (!file) {
        this.$alert('提示', '请先选择编排单')
        return
      }
      if (this.isCanAction(file)) {
        const bool = await this.$confirm('提示', '是否确定撤销')
        if (bool) {
          try {
            const res = await MediaApi.revokePubList({id: file.id})
            
            this.$message.success('撤销成功')
            this.fetchList()
          } catch (error) {
            console.log('MediaApi.revokePubList', error)
          }
        }
      }  
    },
    _handleRefresh() {
      console.log('刷新')
      this.sort.orderType = 0
      this.page.current = 1
      this.fetchList()
      this.$message.success('刷新成功')
    },
     async _handleExport() {
      var file = this.getActiveItem()
      if(this.allSize){
        this.$alert('提示', '此操作不支持所有页')
        return
      }
      if (!file) {
        this.$alert('提示', '请先选择编排单')
        return
      }
      //判断是否生效日期过期日期一致
      var ids = []
      var isSame = true
      if (file instanceof Array) {
        var firstStartTime = file[0].startDate
        var firstEndTime = file[0].endDate
        file.forEach(item => {
          ids.push(item.id)
          if (item.startDate !== firstStartTime) {
            isSame = false
          }
          if (item.endDate !== firstEndTime) {
            isSame = false
          }
        })
      }else{
        ids.push(file.id)
      }
      if(!isSame){
        this.$alert('提示', '请先选择同一时间段的编排单')
        return
      }
      console.log('导出===============')
      this.updateLoading(true)
      const res = await MediaApi.getPubProgramExportList({
        ids
      })
      this.updateLoading(false)
      //处理拼凑导出文档的头
      var excelDataFields = {
        '序号':'number',
        '节目名称':'name',
        '节目时长':'times',
      }
      var keyList = res.key
      keyList.forEach(key => {
        excelDataFields[key] = key
      })
      this.excelDataFields = excelDataFields

      //处理拼凑导出文档的内容
      var dataList = res.list
      dataList.forEach(item => {
        item.startTime.forEach((time,index) => {
          var key = keyList[index]
          item[key] = time
        })
      })
      return dataList
    },

    pageChange({page: current, limit: size}) { // 分页改变
      this.page = {
        ...this.page,
        current: size != this.page.size ? 1 : current,
        size
      } 
      this.fetchList()
    },
    initFetchParams() {
      const {
        checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys
      } = this.checkLog
      let queryType = -1
      let typeIdsMap = {
        '1': [],
        '2': [],
        '3': []
      }
      let type3Arr = []
      checkedNodes.forEach(item => {
        if (typeIdsMap[item.type]) { typeIdsMap[item.type].push(item.id) }
        if (item.type > queryType) {queryType = item.type}
        if (item.type == 3) {
          type3Arr.push(item)
        }
      })

      if (queryType === -1) {
        return false
      } else {
        return [typeIdsMap[queryType], queryType, type3Arr]
      }
    },
    async fetchList({noMenu} = {}) {
      if (this.t3arr.length < 1 && !noMenu && !this.lastFetchTop) {
        this.mediaData = []
        this.page.total = 0
        this.page.current = 1
        return 
      }
      this.listFetching = true
      try {
        const {current, size} = this.page
        const { checkedNodes } = this.checkLog
        const groupScreens = this.t3arr.length > 0 ? this.t3arr.map(item => item.groupScreen) :
          checkedNodes.map(item => item.groupScreen)
        let params = {
          current,
          size,
          groupScreens
        }
        if (this.sort.orderType) {
          params.orderType = this.sort.orderType
          params.orderParam = this.sort.ordersParam
        }
        // else {
        //   params.orderType = 10
        //   params.orderParam = 'desc'
        // }
        const res = await MediaApi.getPubList(params)
        const data = res.data || {}
        this.mediaData = data.records || []
        this.page.total = Number(data.total || 0)
        this.page.current = Number(data.current || 0)
        this.page.size = Number(data.size || 0)
        this.lastFetchTop = this.terminalGroupIds.length > 0 ? false : true
      } catch (error) {
        console.log('error', error)
      } finally {
        this.listFetching = false
      }

    },

    async delMedia(file, queryData) {
      let _fileIds
      if (file instanceof Array) {
        _fileIds = file.map(f => f.id)
      } else {
        _fileIds = file ? [file.id] : []
      }
      try {
        const res = await MediaApi.delPubList({
          ids: _fileIds,
          ...queryData
        })
        console.log(res)
        
        this.$message.success('删除成功')
        this.setNeedFetching({change: 'program'})
        this.allSize = false
        this.page.current = 1
        this.fetchList()
      } catch (error) {
        console.warn('delMedia---', error)
      }
    },
    // 选择所有页
    handleChangeAllSize(val) {
      this.allSize = val
      this.$refs.list.clearSelection();
    },
    te(arg) {
      const hasKey = this.$te(arg)
      if (hasKey) {
        const result = this.$t(arg)
        return result
      }
      return arg
    },
    async _openPreView(file) {
      if (!file) {
        this.$alert('提示', '请先选择文件')
        return
      }
      console.log('_openPreView=======',file)
      const passFileType = [ // 能预览的文件类型
        FILETYPE.VIDEO,
        FILETYPE.AUDIO,
        FILETYPE.TEXT,
        FILETYPE.LOCAL_TEXT,
        FILETYPE.QRCODE,
        FILETYPE.NET_PICTURE,
        FILETYPE.PICTURE,
        FILETYPE.WEB_CAPTURE
      ]
      // if (passFileType.indexOf(String(file.type)) === -1) return this.$alert('提示', '对不起，该媒体类型无法预览')
      // 重新获取url的token
      const previewTokenRes = file.path ? await CommonApi.previewToken({path: encodeURIComponent(file.path)}) : null
      const _isText = [FILETYPE.TEXT,FILETYPE.LOCAL_TEXT].some(i => i === String(file.type))
      const _isNET_PICTURE = String(file.type) === FILETYPE.NET_PICTURE
      if (_isText || _isNET_PICTURE) {
        // 获取文本文件内容
        const preContent = await MediaApi.getLocalInfo({path: previewTokenRes ? previewTokenRes : file.path})
        const res = await MediaApi.getInfo({id: file.id}) 
        if(res) {
          let argus = res.argus ? JSON.parse(res.argus) : {}
          let attributes = argus.attributes
          if (attributes && typeof attributes === 'string') {
            attributes = JSON.parse(attributes)
          }
          this.previewDialog = {
            ...this.previewDialog,
            show: true,
            preData: {
              ...argus,
              ...file,
              ...res,
              ...attributes,
              showType: 3,
              _isText
            },
          }
          if(preContent) {
            this.previewDialog.preData.content = preContent
          }
        }
      } else {
        const media = await MediaApi.getInfo({id: file.id}) 
        this.previewDialog = {
          ...this.previewDialog,
          show: true,
          preData: {
            ...media,
            ...file,
            showType: 3,
            _isText: false
          }
        }
         console.log('previewDialog=====',this.previewDialog)
        if(previewTokenRes) {
          this.previewDialog.preData.path = previewTokenRes
        }
      }
       console.log('_openPreView--------------',this.previewDialog)
    },
    updateLoading(val){
      if(val){
        if (this.loading === null) {
          this.loading = this.$loading({
            fullscreen: true,
            text: '正在导出节目数据',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
        }
      }else{
        if (this.loading) {
          this.loading.close()
          this.loading = null
        }
      }
    },
  }
}
</script>
